package collection;

import java.util.ArrayList;
import java.util.List;

/**
 * List可以获取子集
 * List subList(int start,int end)
 * 获取当前List集合中指定范围内的子集，两个下标含头不含尾
 */
public class ListDemo3 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        //向集合中存入10个整数，分别为0-9
        for (int i = 0; i < 10; i++) {
            list.add(i);
        }
        System.out.println(list);
        //获取[3,4,5,6,7]
        List<Integer> subList = list.subList(3,8);
        System.out.println(subList);
        //将子集每个元素扩大10倍
        for(int i=0;i<subList.size();i++){
            int n = subList.get(i);
            n = n * 10;
            subList.set(i,n);
        }
        //[30,40,50,60,70]
        System.out.println(subList);
        /*
            对子集的操作就是对原集合对应元素的操作
         */
        System.out.println(list);

        //将集合中的2-8删除
        list.subList(2,9).clear();
        System.out.println(list);//[0,1,9]
    }
}
